package com.wys.proxydemo.myjdk;

import java.lang.reflect.Method;

/**
 * @author godShan
 * @Description:
 * @date 2019/5/6 10:05
 */
public class GSChuShi implements GSInvocationHandler {

    private Object target;

    public Object getInstance(Object target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return GSProxy.newProxyInstance(new GSClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(target, args);
        after();
        return obj;
    }

    private void after() {
        System.out.println("客官您慢点，您的菜马上就到！");
    }

    private void before() {
        System.out.println("请问客官您需要点什么？小店所有菜系色香味俱全！");
    }

}
